package com.epam.command.admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.epam.command.logic.Command;
import com.epam.command.logic.ManagerLogic;
import com.epam.entity.User;
import com.epam.entity.User.Role;
import com.epam.util.ConfigurationManager;

public class UpdateUserCommand implements Command {

	
	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) {
		
		Role role = Enum.valueOf(User.Role.class, request.getParameter("role"));
		String login = request.getParameter("login");
		String page = ConfigurationManager.getConfig(ConfigurationManager.OPERATION_SUCCESSFUL);;
		
		if (ManagerLogic.updateUser(login, role)) {
			
			request.setAttribute("message", "Update successful");
			
		} else {
			
			request.setAttribute("message", "User not found");
		}
		
		return page;
		
	}

}
